<%@page import="java.rmi.RemoteException"%>
<%@page import="java.sql.SQLException"%>
<%@page import="exception.UserNameExistException"%>
<%@page import="org.w3c.dom.Document"%>
<%@page import="exception.RegistrationException"%>
<%@page import="exception.NotRegisteredException"%>
<%@page import="java.rmi.Naming"%>
<%@page import="server.ForumHandlerInt"%>

<%@ include file="serverConnection.jsp" %>
<%
	
     
   try
	{
		//out.println(request.getMethod());
		//forum.login(request.getParameter( "userName" ),request.getParameter( "password" ));
		//forum.register(request.getParameter( "userName" ),request.getParameter( "password" ),123,"fgf","vb","dgh");
   		String premission = "";
		forum.register(request.getParameter( "userName" ),request.getParameter( "password" ),
				Integer.parseInt(request.getParameter( "id" )),request.getParameter( "email" ),
				request.getParameter( "firstName" ),request.getParameter( "lastName" ));
		premission = forum.login(request.getParameter("userName" ),request.getParameter( "password" ));
		session.setAttribute("permission",premission);
   		//if we have arrived here from registration page we will set user name and password
		//in the session
		if (request.getParameter("userName")!=null )
			session.setAttribute("userName",request.getParameter("userName"));

		if (request.getParameter("password")!=null)
			session.setAttribute("password",request.getParameter("password"));
   %>
   		<h2 id="userAu">ok</h2>
   
   <% 
	}
   catch(UserNameExistException ue){
	   %>
	   <h2 id="userAu">user already exist!</h2>
	   <% 	   
   }
   
   catch(NotRegisteredException e){
%>
<h2 id="userAu">user doesn't registered! please try again...</h2>
<% 
   }
   catch(SQLException s){
	   //System.out.println("SQL EXCEPTION");
	   
	   response.sendError(response.SC_INTERNAL_SERVER_ERROR,
		"SQL server is down");
	
		response.flushBuffer();
		return;
   }
catch(RemoteException u){
	   
	   response.sendError(response.SC_INTERNAL_SERVER_ERROR,
		"forum server is down");
	
		response.flushBuffer();
		return;
   }
   //catch(Exception t){
  // }
%>
</html>